home *** CD-ROM | disk | FTP | other *** search
- Path: jhunix.hcf.jhu.edu!hbien
- From: hbien@jhunix.hcf.jhu.edu (Harold Bien)
- Newsgroups: comp.object,comp.lang.c++,comp.ai.alife,sci.comp-aided
- Subject: Re: [Q] Growing Objects
- Followup-To: comp.object,comp.lang.c++,comp.ai.alife,sci.comp-aided
- Date: 28 Jan 1996 05:59:20 GMT
- Organization: HCF - Johns Hopkins University, Baltimore, Maryland, USA
- Message-ID: <4ef3bo$mjo@news.jhu.edu>
- References: <30FE8297.41C6@bme.jhu.edu> <RMARTIN.96Jan20093428@rcm.oma.com>
- NNTP-Posting-Host: 128.220.2.5
- X-Newsreader: TIN [version 1.2 PL2]
-
- Robert C. Martin (rmartin@oma.com) wrote:
-
- [deleted]
-
- : What you have described is known as a finite state machine. A finite
- : state machine reacts to particular events in ways that depend upon the
- : state of the machine. In your case, you have only one event: Run; but
- : you have many states.
-
- [deleted]
-
- : You can use pointers to member functions to control your state
- : machine. However I recommend against it. It may be, after some time,
- : that you find that you need other events beside 'run'. For example,
- : you may wish to tell each cell to "print"; and would like the behavior
- : of "print" to depend upon the state of the cell. Other events seem
- : likely as well: RespondToLight, RespondToHunger, RespondToAttack,
- : etc. Each of these stimuli will very likely depend upon the state.
- : If you use the member function approach, you will find that every time
- : the cell changes state, you will have to shuttle around many pointers
- : to member functions. The chances of error are high.
-
- [deleted]
-
- You bring up some interesting points. Though I readily see the
- logic in your approach, I'm curious as to why my approach is
- "incorrect." The Run() function is the main function called and will
- dispatch to the changing RealRun() function. However, the Run() function
- doesn't really do much except call _OTHER_ subfuctions. Therefore,
- should I need new methods like RespondToLight() et al. I will only have
- to put them in the RealRun() function relevant to the state. Am I
- overlooking something? I have yet to implement anything, but am afraid
- of commiting myself to something which will not stand up to the test of
- time. Thanks for your respons.
-